#pragma once
using namespace std;
#include<iostream>
#include<string.h>

//class Array
//{
//public:
//    // 构造函数
//    Array(int count) {
//        this->count = count;
//        cout << "Array()" << endl;
//    }
//    // 拷贝构造函数
//    Array(const Array& arr) {
//        // 浅拷贝
//        this->count = arr.count;
//        cout << "Array(const Array & arr)" << endl;
//    }
//    void printAddress() {
//        cout << "address: " << &count << endl;
//    }
//    // 析构函数
//    ~Array() {
//        cout << "~Array(): " << count << endl;
//    }
//    void setCount(int count) { this->count = count; }
//    int getCount() { return count; }
//private:
//    int count;
//};

//class Array1
//{
//public:
//    Array1(int count) {
//        this->count = count;
//        Arr = new int[count];
//        cout << "Array()" << endl;
//    }
//    Array1(const Array1& arr) {
//        this->count = arr.count;
//        // 深拷贝
//        this->Arr = new int[count];
//        for (int i = 0; i < count; i++) {
//            this->Arr[i] = arr.Arr[i];
//        }
//        cout << "Array(const Array & arr)" << endl;
//    }
//    ~Array1() {
//        delete[] Arr;
//        Arr = nullptr;
//        cout << "~Array(): " << count << endl;
//    }
//    void printAddress() {
//        cout << "address: " << Arr << endl;
//    }
//    void setCount(int count) { this->count = count; }
//    int getCount() { return count; }
//private:
//    int count;
//    int* Arr;
//};

class Str {//Str类的一个对象，里面放一个数组（模拟的）
	public:

		Str() {
			this->Arr = new char;
			this->sz = 1;//设为1，避免 /0 产生影响
			}

		Str(const char* strin) {
			int count = 0;
			while (strin[count]!= '\0')
			{
				count++;
			}
			if (strin[count]=='\0') {
				count++;
			}
			this->sz = count;
			this->Arr = new char[count];//牛逼啊C++，太方便了！
			for (int i = 0; i < count;i++) {
				Arr[i] = strin[i];
			}
		}

		Str (const Str& str) {//拷贝构造函数 = /（Str& str）
			this->sz = str.sz;
			int count = this->sz;
			char* arr = new char[count];
			for (int i = 0; i < count;i++) {
				arr[i] = str.Arr[i];
			}
			this->Arr = arr;
		}

		Str(int f,char c) {
			this->Arr = new char[f+1];//多一位放 \0 
			for (int i=0; i < f;i++) {
				this->Arr[i] = c;
			}
			//最后一位置为‘\0’(下表为f)
			this->Arr[f] = '\0';
			this->sz = f + 1;
		}

		~Str()
		{
		delete[] Arr;
        Arr = nullptr;
		sz = 0;
		}
		//声明接口
		void PrtArr() {
			int count = this->sz;
			/*while (this->Arr[count]!='\0')
			{
				cout << this->Arr[count] << ' ';
				count++;
			}*/
			if (count == 1) {
				cout << "字符串为空！" << endl;
					return ;
			}
			for (int i = 0; i < count;i++) {
				cout << this->Arr[i] << ' ';
			}
			cout << endl;
		}
	private:
		char* Arr;
		int sz;
};